package com.ruoyi.web.controller.mes;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.kt.mes.domain.Bom;
import com.kt.mes.service.IBomService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * BOMController
 *
 * @author lzc
 * @date 2021-01-23
 */
@RestController
@RequestMapping("/mes/bom")
public class BomController extends BaseController
{
    @Autowired
    private IBomService bomService;

    /**
     * 查询BOM列表
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:list')")
    @GetMapping("/list")
    public AjaxResult list(Bom bom)
    {
        List<Bom> list = bomService.selectBomList(bom);
        return AjaxResult.success(list);
    }

    /**
     * 导出BOM列表
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:export')")
    @Log(title = "BOM", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Bom bom)
    {
        List<Bom> list = bomService.selectBomList(bom);
        ExcelUtil<Bom> util = new ExcelUtil<Bom>(Bom.class);
        return util.exportExcel(list, "bom");
    }

    /**
     * 获取BOM详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bomService.selectBomById(id));
    }

    /**
     * 新增BOM
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:add')")
    @Log(title = "BOM", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Bom bom)
    {
        return toAjax(bomService.insertBom(bom));
    }

    /**
     * 修改BOM
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:edit')")
    @Log(title = "BOM", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Bom bom)
    {
        return toAjax(bomService.updateBom(bom));
    }

    /**
     * 删除BOM
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:remove')")
    @Log(title = "BOM", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bomService.deleteBomByIds(ids));
    }
}